package com.example.ymm.modules1.service.impl.user;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.ymm.base.BaseServiceImpl;
import com.example.ymm.model.TableList;
import com.example.ymm.model.YmPageDto;
import com.example.ymm.modules1.entity.my.user.DbOrderItem;
import com.example.ymm.modules1.mapper.my.user.DbOrderItemMapper;
import com.example.ymm.modules1.query.DbOrderItemQueryCriteria;
import com.example.ymm.modules1.service.user.DbOrderItemService;
import com.example.ymm.util.QueryHelpPlus;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
@Slf4j
public class DbOrderItemServiceImpl extends BaseServiceImpl<DbOrderItemMapper, DbOrderItem> implements DbOrderItemService {

    @Override
    public TableList<DbOrderItem> list(DbOrderItemQueryCriteria criteria, YmPageDto pageDto) {
        getPage(pageDto);
        List<DbOrderItem> maps = baseMapper.getOrderItemList(criteria);
        PageInfo<DbOrderItem> pageInfo = new PageInfo<>(maps);
        TableList<DbOrderItem> tableList=new TableList<>(pageInfo);
        return tableList;
    }

    public List<DbOrderItem> queryAll(DbOrderItemQueryCriteria criteria) {
        QueryWrapper predicate = QueryHelpPlus.getPredicate(DbOrderItem.class, criteria);
        predicate.orderByDesc("create_time");
        List<DbOrderItem> result =baseMapper.selectList(predicate);
        return result;
    }
}
